package com.jia.lidao.ui.personal.adapter;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jia.lidao.R;
import com.jia.lidao.enity.Goods;
import com.jia.lidao.others.ui.fragment.OrderDetailActivity;
import com.jia.lidao.others.utils.DisplayUtil;
import com.jia.lidao.utils.ImgLoaderUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jia on 17/12/16.
 */

class OrderDetailAdapter extends BaseAdapter{

    private Context context;

    private List<Goods> goodsList;

    public OrderDetailAdapter(Context context,List<Goods> list){
        this.context=context;
        goodsList=new ArrayList<>();
        goodsList.addAll(list);
    }

    @Override
    public int getCount() {
        return goodsList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if(view==null){
            viewHolder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.item_order_detail_list,null);
            viewHolder.goodImg=(ImageView)view.findViewById(R.id.order_icon_img);
            viewHolder.goodName=(TextView)view.findViewById(R.id.order_name_tv);
            viewHolder.goodNum=(TextView)view.findViewById(R.id.order_num_tv);
            viewHolder.goodPrice=(TextView)view.findViewById(R.id.order_price_tv);
            view.setTag(viewHolder);
        }else {
            viewHolder=(ViewHolder)view.getTag();
        }
        ImgLoaderUtil.displayImage(goodsList.get(i).goods_pic.replace("https://","http://"),viewHolder.goodImg);
        viewHolder.goodNum.setText("x"+goodsList.get(i).quantity);
        viewHolder.goodPrice.setText("¥"+ DisplayUtil.double2String(goodsList.get(i).price));
        viewHolder.goodName.setText(goodsList.get(i).goods_name);
        return view;
    }


    class ViewHolder{

        ImageView goodImg;

        TextView goodName;

        TextView goodPrice;

        TextView goodNum;

    }
}
